package com.yunbiao.ybboardapi.utils;

import java.lang.reflect.Method;

public class SystemPropertyUtils {
    private static SystemPropertyUtils systemPropertyUtils;
    private SystemPropertyUtils(){}

    public static SystemPropertyUtils getInstance(){
        if (systemPropertyUtils==null){
            systemPropertyUtils=new SystemPropertyUtils();
        }
        return systemPropertyUtils;
    }

    public String get(String key, String defaultValue) {
        String value = defaultValue;
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class, String.class);
            value = (String) get.invoke(c, key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return value;
        }
    }

    public int getInt(String key, int defaultValue) {
        int value = defaultValue;
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("getInt", String.class, Integer.class);
            value = (int) (get.invoke(c, key, defaultValue));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return value;
        }
    }
}
